/**
  * Author: Mei
  * Date: 2020-11-22 19:41
  * Description: 
  *
  */
#include <iostream>
#include <future>

int do_get_value() { return 10; }

void th1(std::shared_future<int> sf) {
    std::cout << sf.get() << std::endl;
}

void th2(std::shared_future<int> sf) {
    std::cout << sf.get() << std::endl;
}
//特点：std::sharted_future可以被复制，std::future是不可以的被复制的。
int main() {
    std::future<int> fut = std::async(do_get_value);
    //std::shared_future<int> sf2(std::move(fut));
    //std::shared_future<int> sf2 = fut.share();
    //std::thread t1(th1, sf2);
    //std::thread t2(th1, sf2);

    //t1.join();
    //t2.join();
    std::promise<int> pro;
    std::shared_future<int> sf1(pro.get_future());
    std::thread t1(th1, sf1);
    std::thread t2(th1, sf1);
    pro.set_value(110);
    t1.join();
    t2.join();
}